<?php

namespace app\admin\controller;

use system\model\Admin;

/**
 * 登录管理控制器
 * Class Login
 * @package app\admin\controller
 */
class Login
{
    public function index(Admin $admin)
    {
    	//测试数据库连接
//			$res = Db::table('admin')->get();
//			p($res);
		//测试通过模型操作数据
			//$res = (new Admin())->get();
			//p($res);
		if(IS_POST)
		{
//			echo p(1);die;
			$res = $admin->login();

			if($res['valid'])
			{
				//执行成功
				return message($res['msg'],'admin.entry.index','success');
				//message($res['msg'], u('admin.entry.index'), $type = 'success', $timeout = 2 );
			}else{
				//执行失败
				return message($res['msg'],'back','error');
				//message($res['msg'],'back','error');
			}
		}
        //加载模板文件
		return View::make();
    }
    /**
	 * 验证码
	 */
    public function code()
	{
		Code::width(100)->height(50)->num(1)->make();
	}
	/**
	 * 退出登录
	 */
	public function out()
	{
		//删除所有数据
		Session::flush();

//		go('/login');

		go(__ROOT__.'/index.php/login');


//		go(__ROOT__.'/index.php?s=admin/login/index');
	}
}